package com.gu.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gu.VO.PropertyVO;
import com.gu.dao.ApartmentDAO;
import com.gu.entity.ApartmentDO;
import com.gu.service.ApartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.ArrayList;
import java.util.List;

/**
 * @ProjectName: apartment-management-center
 * @Package: com.gu.service.impl
 * @ClassName: ApartmentServiceImpl
 * @Author: gusongliao
 * @Description: 公寓服务层实现类
 * @createDate 2021/01/27 17:04
 */
@Service
public class ApartmentServiceImpl implements ApartmentService {

    @Autowired
    private ApartmentDAO apartmentDAO;

    /**
     * 查找未入住的房间
     * @param entity
     * @return
     */
    @Override
    public List<String> getNotUsedApartmentRoomNumber(ApartmentDO entity){
        return apartmentDAO.getNotUsedApartmentRoomNumber(entity);
    }
    /**
     * 查找已入住的房间
     * @param entity
     * @return
     */
    @Override
    public List<String> getUsedApartmentRoomNumber(ApartmentDO entity){
        return apartmentDAO.getUsedApartmentRoomNumber(entity);
    }

    @Override
    public PageInfo listApartment(Integer pageNum, Integer pageSize,ApartmentDO apartmentDO) {
        PageHelper.startPage(pageNum,pageSize);
        PageInfo pageInfo = PageInfo.of(apartmentDAO.listApartment(apartmentDO));
        return pageInfo;
    }

    @Override
    public int updateApartment(Integer userId, Integer id) {
        return apartmentDAO.updateApartment(userId, id);
    }

    @Override
    public int updateApartmentUserId(Integer userId, Integer id) {
        return apartmentDAO.updateApartmentUserId(userId, id);
    }

    @Override
    public List<PropertyVO> getApartmentByUser(Integer userId) {
        List<ApartmentDO> apartmentDOList = apartmentDAO.getApartmentByUser(userId);
        List<PropertyVO> propertyVOList = new ArrayList<>();
        apartmentDOList.forEach(f ->{
            PropertyVO propertyVO = new PropertyVO();
            propertyVO.setApartmentCode(f.getId());
            propertyVO.setApartmentName("" + f.getBuildingNumber() + "-" + f.getUnitNumber() + "-" +  f.getFloorNumber() + "-" +  f.getRoomNumber());
            propertyVOList.add(propertyVO);
        });
        return propertyVOList;
    }


}
